package com.recsmile.rpc.consumer.net.codec;

import com.recsmile.rpc.bo.RpcMessageRequest;
import com.recsmile.rpc.consumer.ServerStartApplicationContext;
import com.recsmile.rpc.consumer.net.RpcMessageRecvHandlerTask;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.util.Map;

/**
 * Created by Administrator on 2016/8/7.
 */
public class MessageRecvHandler extends ChannelInboundHandlerAdapter{

    private Map<String,Object> serviceMap;

    public MessageRecvHandler(Map<String, Object> serviceMap) {
        this.serviceMap = serviceMap;
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ServerStartApplicationContext.submit(new RpcMessageRecvHandlerTask((RpcMessageRequest)msg, ctx, serviceMap));
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        //super.exceptionCaught(ctx, cause);
        cause.printStackTrace();
    }



}
